//
//  ListOptionsViewController.m
//  smarthings
//
//  Created by Stefan Tsvyatkov on 10/26/14.
//  Copyright (c) 2014 Stefan Tsvyatkov. All rights reserved.
//

#import "ListOptionsViewController.h"
#import "Smarthings.h"

@implementation ListOptionsViewController

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return self.list.count;
    }
    else {
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TypeCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TypeCell"];
    }
    
    cell.textLabel.text = [(SMTGeneralThingsObject *)self.list[indexPath.row] uuid];
    cell.detailTextLabel.text = [(SMTGeneralThingsObject *)self.list[indexPath.row] name];
    if (indexPath.row == self.selectedIndex) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedIndex = indexPath.row;
    [self.delegate indexHasBeenChosen:indexPath.row];
    [self.navigationController popViewControllerAnimated:YES];
}


@end
